/*
 * Copyright 2010 Christoph Widulle (christoph.widulle@googlemail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */



package com.android1.amarena2d.nodes;

import com.android1.amarena2d.nodes.behavior.HasColor;
import com.android1.amarena2d.nodes.behavior.LifecyleTick;
import com.android1.amarena2d.texture.BitmapFont;
import com.android1.amarena2d.texture.ManagedBitmapFont;
import com.badlogic.gdx.graphics.Color;

/**
 * Shouldn't be used if you have more Textlabels from the same font.
 */
public class SimpleLabel extends BaseLeafEntity implements LifecyleTick, HasColor {

    protected FontNode fontNode;
    protected TextLabel label;


    public SimpleLabel(String text, float x, float y, Color color) {
        this(x, y, color);
        setText(text);
    }
//

    public SimpleLabel(String text, float x, float y) {
        this(text, x, y, Color.WHITE);
    }

    public SimpleLabel(float x, float y, Color color) {
        this(engine.getFontManager().getDefaultFont(), x, y, color);
    }

    public SimpleLabel(ManagedBitmapFont font, float x, float y, Color color) {
        position.set(x, y);
        fontNode = new FontNode(font);
        label = fontNode.createLabel();
        label.setXY(position.x, position.y);
        setColor(color);
    }

    public SimpleLabel setAlign(BitmapFont.HAlignment align) {
        label.setAlign(align);
        return this;
    }

    public String getText() {
        return this.label.getText();
    }

    public SimpleLabel setText(String text) {
        this.label.setText(text);
        return this;
    }

    @Override
    public void init() {
        super.init();
        fontNode.init();
    }

    @Override
    public void dispose() {
        super.dispose();
        fontNode.dispose();
    }


    @Override
    public void enter() {
        super.enter();
        fontNode.enter();
    }

    @Override
    public void exit() {
        super.exit();
        fontNode.exit();
    }

    @Override
    public void render() {
        fontNode.render();
    }

    @Override
    public void setColor(float r, float g, float b) {
        this.label.setColor(r, g, b);
    }

    @Override
    public void setColor(Color color) {
        label.setColor(color);
    }

    @Override
    public Color getColor() {
        return label.getColor();
    }
}